package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.InspectionRecord;
import com.amsp.oa.oademo.mapper.InspectionRecordMapper;
import com.amsp.oa.oademo.service.InspectionRecordService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;

@Service
public class InspectionRecordServiceImpl extends ServiceImpl<InspectionRecordMapper, InspectionRecord>
        implements InspectionRecordService {

    @Override
    public IPage<InspectionRecord> getPage(Integer pageNum, Integer pageSize, String keyword) {
        LambdaQueryWrapper<InspectionRecord> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(keyword)) {
            wrapper.like(InspectionRecord::getInspectionDepartment, keyword)
                    .or()
                    .like(InspectionRecord::getMainInspectionItems, keyword);
        }
        wrapper.orderByDesc(InspectionRecord::getCreateTime);
        return page(new Page<>(pageNum, pageSize), wrapper);
    }

    @Override
    public boolean saveBatch(List<InspectionRecord> records) {
        return super.saveBatch(records);
    }
}